// 变量声明
var Jxc_typename     = '',//弹窗品种名称
    Jxc_tradeid      = '',//弹窗交易订单号
    Jxc_status       = 0,//弹窗交易方向  买入 卖出
    Jxc_beginpoint   = 0,//弹窗交易价格
    Jxc_updateprofit = 0,//用户修改止盈后的点位
    Jxc_updateloss   = 0,//用户修改止损后的点位
    Jxc_dianshu      = 0,  //新增订阅弹窗的买入价格
    Jxc_otherdianshu = 0, //新增订阅弹窗做判断点数是买入还是卖出用的
    Jxc_PingDing     = 0, //平仓订单号
    Jxc_PingPingZ    = 0, //平仓品种
    Jxc_PingFang     = 0, //平仓方向
    Jxc_baoying_zhisun = 0 , //此处定义此全局变量，用于判断是否修改了止损（保盈功能使用）
    idMyurl          = GetQueryString("typename"), //点击进入的品种
    myurl            = '',  //持仓品种
    Jxc_tjtradeid    = 0, // 推进止损订单号
    Jxc_tjtypename   = 0, // 推进止损品种
    Jxc_losspoint    = '',
    labels           = ['FXXAUUSD','FXEURUSD','FXGBPUSD','FXUSDJPY','FXUSDCHF','FXUSDCAD' ,'FXAUDUSD','FXEURGBP','FXEURJPY','FXEURAUD','FXEURCHF','FXEURCAD','FXGBPCHF','FXGBPJPY' ,'FXCADJPY','FXAUDCAD','FXCHFJPY','FXAUDJPY'];  //共有的品种
// 数据调用
$(function(){

    if(idMyurl != null){ //地址有typename参数 进入订阅页面
        myurl +=  idMyurl;
    }else{
        // 持仓品种拼串 地址没有typename参数 进入持仓页面
        if(alltype != ''){
            myurl += alltype;
        }
    }
    //判断页面有没有这个品种，没有返回一个页面，反之进入页面
    if(myurl !=null && myurl.toString().length>1){
        if($.inArray(myurl,labels>=1)){
            // console.log('品种存在');
        }else{
            // console.log('品种不存在')
        }
    };
    setintervalAjax(); //单个品种止盈止损数据调用
    if((starttime*1000) > nowtime){
        clearInterval(timer);
    }else if((endtime*1000) < nowtime){
        clearInterval(timer);
    }else{
        clearInterval(timer);
        timer = setInterval(setintervalAjax,1000);
    }
    // 平仓操作隐藏
    $('#goCanel').click(function(){
        $('.pingCAlert').hide();
    })
})
// 判断地址栏
function GetQueryString(name){  //name 写入地址栏想要获取的参数前面的值
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}
//判断用户有没有登录
function localStorageJxc(){
    if(issession == ''){
        $('#header').hide();
    }else{
        $('#header').show();
    }
}
//定时刷新点位
function  setintervalAjax() {
    var str = '';
    var rounder = (new Date()).getTime();
    var url = "http://db2015.wstock.cn/wsDB_API2/stock.php?t="+ (new Date()).getTime()+"&symbol="+myurl+"&query=Date,Symbol,SP1,BP1,Name,LastClose,Open,High,Low&u=liyunhe1228&p=liyunhe1228&r_type=2&num=20";
    $.ajax({
        type : "get",
        async : false, //同步请求
        url : url,
        data : '',
        timeout:1000,
        success:function(d){
            //判断品种涨跌浮动情况
            if(typeof d == "object"){
                for(var i =0 ;i < d.length;i++){
                    if(idMyurl == d[i].Symbol){
                        $('#LastOpen').find('span:eq(0)').text(d[i].Open);
                        $('#LastOpen').find('span:eq(1)').text(d[i].LastClose);
                        $('#LastOpen').find('span:eq(2)').text(d[i].High);
                        $('#LastOpen').find('span:eq(3)').text(d[i].Low);
                        /*$('#Purchase').attr('onclick','showDiv(this,0,'+d[i].BP1+','+d[i].SP1+')');
                        $('#SellOut').attr('onclick','showDiv(this,1,'+d[i].BP1+','+d[i].SP1+')');*/
                        if($("input[name=sell"+d[i].Symbol+"]") && $("input[name=buy"+d[i].Symbol+"]")){
                            var selldata=$("input[name=sell"+d[i].Symbol+"]").val();
                            var buydata=$("input[name=buy"+d[i].Symbol+"]").val();
                        }
                        if(selldata == d[i].BP1){
                            Drefresh('#buyNum','gray font_one','<input type="hidden" name=sell'+d[i].Symbol+' value="'+d[i].BP1+'"/>',d[i].BP1,'');
                        }else if(selldata < d[i].BP1){
                            Drefresh('#buyNum','red font_one','<input type="hidden" name=sell'+d[i].Symbol+' value="'+d[i].BP1+'"/>',d[i].BP1,'<img src="'+j_top+'" alt=""/>');
                        }else{
                            Drefresh('#buyNum','green font_one','<input type="hidden" name=sell'+d[i].Symbol+' value="'+d[i].BP1+'"/>',d[i].BP1,'<img src="'+j_down+'" alt=""/>');
                        }
                        if(buydata == d[i].SP1){
                            Drefresh('#saleNum','gray font_one','<input type="hidden" name=buy'+d[i].Symbol+' value="'+d[i].SP1+'"/>',d[i].SP1,'');
                        }else if(buydata < d[i].SP1){
                            Drefresh('#saleNum','red font_one','<input type="hidden" name=buy'+d[i].Symbol+' value="'+d[i].SP1+'"/>',d[i].SP1,'<img src="'+j_top+'" alt=""/>');
                        }else{
                            Drefresh('#saleNum','green font_one','<input type="hidden" name=buy'+d[i].Symbol+' value="'+d[i].SP1+'"/>',d[i].SP1,'<img src="'+j_down+'" alt=""/>');
                        }
                        str +='<input type="hidden" name="sell'+d[i].Symbol+'" value='+d[i].BP1+'>';
                        str +='<input type="hidden" name="buy'+d[i].Symbol+'" value='+d[i].SP1+'></li>';
                    }else{
                        str +='<input type="hidden" name="sell'+d[i].Symbol+'" value='+d[i].BP1+'>';
                        str +='<input type="hidden" name="buy'+d[i].Symbol+'" value='+d[i].SP1+'></li>';
                    }
                }
                $('#j_bottom').html(str);
            }
        }
    })
}
// 定时刷新点位html函数
function Drefresh(id,colour,quotation,quotations,img){
    $(id).attr('class',colour);
    $(id).html(quotation+quotations+img)
    // 备份
    // $('#saleNum').attr('class','red');
    // $('#saleNum').html('<input type="hidden" name=buy'+d[i].Symbol+' value="'+d[i].SP1+'"/>'+d[i].SP1+'<img src="'+j_top+'" alt=""/>')
}
//我的订阅 -> 当前价格
function current_price(buy_status,typename){
    var price='';
    if(buy_status == '买入'){
        var newprice = price = $("input[name=buyFX"+typename+"]").val();
    }else{
        var newprice =  price = $("input[name=sellFX"+typename+"]").val();
    }
    var oldprice=$("input[name=curr_FX"+typename+"]").val();  //上一个0.3s的值

    if(oldprice == ''){  //如果页面第一次加载
        $(".orderTab #FX"+typename).attr('class','gray font_one');
        $(".orderTab #FX"+typename).html(price);
    }else{
        var res_price = parseFloat(price) - parseFloat(oldprice);

        if(res_price > 0){   //如果当前的数据大于上一个0.3s的值
            $(".orderTab #FX"+typename).attr('class','red font_one');
            $(".orderTab #FX"+typename).html(price);
        }else if(res_price < 0){ //如果当前的数据小于上一个0.3s的值
            $(".orderTab #FX"+typename).attr('class','green font_one');
            $(".orderTab #FX"+typename).html(price);
        }
    }

    $("input[name=curr_FX"+typename+"]").val(newprice);
}
//我的订阅 -》 盈亏点位
/*function profile_loss(buy_status,typename,begin_point) {
 console.log(1245);
 if (buy_status == '买入') {    // 拿到当前实时变化的价格
 var price = $('input[name=buyFX'+typename+']').val();
 } else {
 var price = $('input[name=sellFX'+typename+']').val();
 }
 if(buy_status == '卖出'){
 if (typename == 'XAUUSD') {
 // var lastprice = MyCallList(begin_point,price,1,10,2);
 var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(1))*10).toFixed(2);
 } else if (typename == 'NYOL20'){
 // var lastprice = MyCallList(begin_point,price,0.1,100,2);
 var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(0.1))*100).toFixed(2);
 }else if( typename.indexOf('JPY')>0){
 // MyCallList(begin_point,price,0.1,100,3)
 var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(0.1))*100).toFixed(3);
 }else{
 var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(0.001))*10000).toFixed(5);
 }
 }else{
 if (typename == 'XAUUSD') {
 var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(1))* 10).toFixed(2) ;
 } else if (typename == 'NYOL20'){
 var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(0.1))* 100).toFixed(2);
 }else if( typename.indexOf('JPY')>0){
 var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(0.1))* 100).toFixed(3);
 }else{
 var lastprice = ((parseFloat(price) - parseFloat(begin_point)-parseFloat(0.001))* 10000).toFixed(5);
 }
 }

 var oldprice = $("input[name=oldpot_FX"+typename+"]").val();
 if(oldprice != ''){
 var newpotprice = parseFloat(lastprice) - parseFloat(oldprice);
 if(newpotprice > 0){
 $("#last_FX"+typename).css({'color':'#f7512b'});
 }else if(newpotprice < 0){
 $("#last_FX"+typename).css({'color':'#27a885'});
 }
 }else{
 $("#last_FX"+typename).css({'color':'#8c8c8c'});
 }
 $("#last_FX"+typename).html('<input type="hidden" name=oldpot_FX'+typename+' />'+parseFloat(lastprice));
 $("input[name=oldpot_FX"+typename+"]").val(parseFloat(lastprice));
 }*/
//  我的订阅盈亏点位函数封装
function MyCallList(begin_point,price,num,Multiplication,sub){
    var lastprice = (( parseFloat(begin_point)-parseFloat(price)-parseFloat(num))*Multiplication).toFixed(sub);
    // console.log(lastprice);
    return lastprice;
}
// 平仓操作
function go_stop(){
    if((starttime*1000) > nowtime){
        msg('本周未开盘');
        return false;
    }else if((endtime*1000) < nowtime) {
        msg('本周已停盘');
        return false;
    }
    var final_point = $("#FD"+Jxc_PingDing+" #last_FX"+Jxc_PingPingZ).text();
    
    if(Jxc_PingFang == '买入'){
        var end_point = $('input[name=buyFX'+Jxc_PingPingZ+']').val();
    }else{
        var end_point = $('input[name=sellFX'+Jxc_PingPingZ+']').val();
    }
    $.ajax({
        url:gourl,
        type:'post',
        async: false,
        data:{end_point:end_point,tradeid:Jxc_PingDing,buy_status:Jxc_PingFang,name:Jxc_PingPingZ,final_point:final_point,pingcangType:pingcangType},
        dataType:'json',
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        success:function(res){
            if(res.status == 1){
                msg('平仓成功');
                window.location.reload();
            }else{
                msg('操作失败，请重新操作！');
            }
        }
    });
}
// 修改弹窗
function Modify(zhiying,zhisun,typeName,tradeid,status,begin_point,target_profit_point,target_loss_point){
    $('#moDify').show();
    $('#profitPoint_').val(zhiying);
    $('#lossPoint_').val(zhisun);
    Jxc_typename     = typeName;
    Jxc_tradeid      = tradeid;
    Jxc_status       = status;
    Jxc_beginpoint   = begin_point;
    Jxc_updateprofit = target_profit_point;
    Jxc_updateloss   = target_loss_point;
    Jxc_baoying_zhisun       = zhisun; //此处定义此全局变量，用于判断是否修改了止损（保盈功能使用）
}
// 平仓操作
function PingChang(tradeid,name,buy_status){
    $('.pingCAlert').show();
    Jxc_PingDing     = tradeid; //平仓订单号
    Jxc_PingPingZ    = name; //平仓品种
    Jxc_PingFang     = buy_status; //平仓方向
}
//修改止盈止损  取消按钮
function goCancel(){
    $('#moDify').hide();
}
//修改止盈点数onkeyup
/*function userInputProfit(type){
    if(type == 1){
        var user_input_point = parseInt($("#profitPoint_").val());
    }else{
        var user_input_point = parseInt($("#lossPoint_").val());
    }
    if(!user_input_point){
        user_input_point=0;
    }
    if(type == 1){
        if(Jxc_typename == 'XAUUSD'){
            var lastpoint = (parseFloat(Jxc_beginpoint) + parseFloat(user_input_point/10)).toFixed(2);
        }else if(Jxc_typename == 'NYOL20'){
            var lastpoint = (parseFloat(Jxc_beginpoint) + parseFloat(user_input_point/100)).toFixed(2);
        }else if(Jxc_typename.indexOf('JPY')>0){
            var lastpoint = (parseFloat(Jxc_beginpoint) + parseFloat(user_input_point/100)).toFixed(3);
        }else{
            var lastpoint = (parseFloat(Jxc_beginpoint) + parseFloat(user_input_point/10000)).toFixed(5);
        }
        Jxc_updateprofit = lastpoint;
    }else{
        if(Jxc_typename == 'XAUUSD'){
            var lastpoint = (parseFloat(Jxc_beginpoint) - parseFloat(user_input_point/10)).toFixed(2);
        }else if(Jxc_typename == 'NYOL20'){
            var lastpoint = (parseFloat(Jxc_beginpoint) - parseFloat(user_input_point/100)).toFixed(2);
        }else if(Jxc_typename.indexOf('JPY')>0){
            var lastpoint = (parseFloat(Jxc_beginpoint) - parseFloat(user_input_point/100)).toFixed(3);
        }else{
            var lastpoint = (parseFloat(Jxc_beginpoint) - parseFloat(user_input_point/10000)).toFixed(5);
        }
        Jxc_updateloss = lastpoint;
    }
}*/
//计算可设置最小点差
function point_diff(typename,current_point,open_point){  // typename 品种  current_point 当前价  open_point 开仓价
    var point_x = parseFloat(current_point) - parseFloat(open_point) ;
    var lastprice = 0;
    var profit_loss_point_x = $('input[name=oldpot_FX'+typename+']').val();
    if (typename == 'XAUUSD') {
        lastprice = Math.ceil(Math.abs(point_x)* 10) ;
    } else if (typename == 'NYOL20'){
        lastprice = Math.ceil(Math.abs(point_x)* 100);
    }else if( typename.indexOf('JPY')>0){
        lastprice = Math.ceil(Math.abs(point_x)* 100);
    }else{
        lastprice = Math.ceil(Math.abs(point_x)* 10000);
    }
    lastprice = lastprice<9?11:lastprice;
    lastprice = profit_loss_point_x > 0?11:lastprice;
    return lastprice;
}
//用户输入止损点数 onkeyup
function userInputLoss(begin_point,buytype,typename,losspoint){
    var user_input_point = losspoint;
    if(!user_input_point){
        user_input_point=0;
    }
    if($.trim(buytype) == '买入'){
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10)).toFixed(2);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(3);
        }else{
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10000)).toFixed(5);
        }
    }else{
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10)).toFixed(2);
            //alert(lastpoint);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(3);
        }else{
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10000)).toFixed(5);
        }
    }
    return parseFloat(lastpoint);
}
//修改止盈点数onkeyup
function userInputProfit(begin_point,buytype,typename,profitpoint){
    var user_input_point = profitpoint;
    if(!user_input_point){
        user_input_point=0;
    }
    if($.trim(buytype) == '买入'){
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10)).toFixed(2);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/100)).toFixed(3);
        }else{
            var lastpoint = (parseFloat(begin_point) + parseFloat(user_input_point/10000)).toFixed(5);
        }
    }else{
        if(typename == 'XAUUSD'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10)).toFixed(2);
            //alert(lastpoint);
        }else if(typename == 'NYOL20'){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(2);
        }else if(typename.indexOf('JPY')>0){
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/100)).toFixed(3);
        }else{
            var lastpoint = (parseFloat(begin_point) - parseFloat(user_input_point/10000)).toFixed(5);
        }
    }
    return parseFloat(lastpoint);
}
//修改止盈止损  确定按钮
function goUpdatePoint(obj){
    $(obj).removeAttr("onclick");
    var updateMyPoint = 0;
    var currprofipoint = $("input[name=sellFX"+Jxc_typename+"]").val(),//当前卖出价格
        currlosspoint = $("input[name=buyFX"+Jxc_typename+"]").val(),//当前买入价格
        profitpoint = parseInt($.trim($("#profitPoint_").val())),//用户输入的止盈点数 input框
        losspoint   = parseInt($.trim($("#lossPoint_").val())); //用户输入的止损点数 input框
    if(!profitpoint) profitpoint = 0;
    if(profitpoint <= 10 || profitpoint >= 500){  //用户输入的止盈点数小于等于10
        $(obj).attr("onclick","goUpdatePoint(this)");
        msg('止盈请输入11-499的整数！');
        updateMyPoint = 0;
        return false;
    }else{
        updateMyPoint = 1;
    }
    
    var set_curr_point = userInputLoss(Jxc_beginpoint,Jxc_status,Jxc_typename,losspoint);//用户修改以后的止损点位
    if(Jxc_baoying_zhisun != losspoint){
        var setpoint  = point_diff(Jxc_typename,currlosspoint,Jxc_beginpoint); //计算以后可设置的最小点差
        if(!losspoint) losspoint = 0;
        if(losspoint <= 10 || losspoint > 50){  //用户输入的止损点数小于等于10 或者大于等于100
            $(obj).attr("onclick","goUpdatePoint(this)");
            msg('止损输入有误，最小为'+setpoint);
            updateMyPoint = 0;
            return false;
        }else if((set_curr_point > currlosspoint) && (Jxc_status == '买入')){ //不能修改
            $(obj).attr("onclick","goUpdatePoint(this)");
            msg('止损输入有误，最小为'+setpoint);
            updateMyPoint = 0;
            return false;
        }else if((set_curr_point < currlosspoint) && (Jxc_status == '卖出')){ //不能修改
            $(obj).attr("onclick","goUpdatePoint(this)");
            msg('止损输入有误，最小为'+setpoint);
            updateMyPoint = 0;
            return false;
        }else{
            updateMyPoint = 1;
        }
    }    
    if(updateMyPoint ==1){
        var set_profit_point = userInputProfit(Jxc_beginpoint,Jxc_status,Jxc_typename,profitpoint);//用户修改以后的止损点位
        $.ajax({
            url:updateurl,
            type: 'post',
            data: {'tradeid':Jxc_tradeid,'profitPoint':profitpoint,'lossPoint':losspoint,'lastProfitPoint':set_profit_point,'lastLossPoint':set_curr_point},
            dataType: "json",
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            success: function(d){
                if(d == 1){
                    $('#moDify').hide();
                    msg('修改成功');
                    window.location.reload();
                }else{
                    $(obj).attr("onclick","goUpdatePoint(this)");
                    msg('修改失败');
                }
            }
        });
    }
}
//显示提示信息弹框
function showDiv(obj,status,point,bpoint){
    if((starttime*1000) > nowtime){
        msg('本周未开盘')
        return false;
    }else if((endtime*1000) < nowtime) {
        msg('本周已停盘');
        return false;
    }
    $('.CallSingle').hide();    //弹窗隐藏
    typename  = idMyurl.substr(2);   //当前订阅品种
    var fangxiang = status == 1?1:0;
    $.ajax({
        url:J_hold,
        type: 'post',
        data: {typename:typename,'point':point,'fangxiang':fangxiang},
        dataType: "json",
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        success: function(d){
            if(d.status == 3){
                msg('持仓状态不能超过3单！')
                $('.CallSingle').hide();
            }else if(d.status == 2){
                msg('请先<a href="'+J_login+'" style="color:#3b9ce0;">登录</a>！',2);
                $('.CallSingle').hide();
            }else if(d.status == 0){
                // msg('同一品种持仓不得超过1单！');
                msg(d.msg);
                $('.CallSingle').hide();
            }else if(d.status == 5){
                msg('请正确操作！');
                $('.CallSingle').hide();
            }else if(d.status == 4){  //未完善资料信息，请先完善资料
                msg("您未完善资料，<a href='"+gowanshan+"' style='color:#3b9ce0;'>请完善资料!</a>",2);
                $('.CallSingle').hide();
            }else{
                $('.CallSingle').show();
                // if(status == 0){
                //     Jxc_dianshu      = bpoint;
                //     Jxc_otherdianshu = point;
                // }else{
                //     Jxc_dianshu      = point;
                //     Jxc_otherdianshu = bpoint;
                // }
                type = status;
            }
        }
    });
}
// 订阅
function handan(obj){
    var myDate = new Date;
    var haomao = myDate.getMilliseconds(); //获取当前毫秒数(0-999)
    localStorage.setItem('date',myDate);
    localStorage.setItem('haomao',haomao);
    var  typename = $.trim(idMyurl.substr(2)),   //品种
        lossWord = $.trim($("#lossWord").val()), //input止盈val
        downWord = $.trim($("#downWord").val()); // input止损val
    var reg=/^[0-9]+$/;
    if(!reg.test(lossWord)) {
        msg('止盈请输入11-499的整数！');
        return false;
    }else if( !isInteger(lossWord)){
        msg('止盈请输入11-499的整数！');
        return false;
    }
    if(!reg.test(downWord)) {
        msg('止损请输入11-50的整数！');
        return false;
    }else if( !isInteger(downWord)){
        msg('止损请输入11-50的整数！');
        return false;
    }
    // 止盈输入提示
    if(lossWord == ''){
        msg('止盈请输入11-499的整数！');
        return;
    }else if(lossWord <= 10){
        msg('止盈请输入11-499的整数！');
        return;
    }else if( lossWord >= 500){
        msg('止盈请输入11-499的整数！');
        return;
    }
    // 止损输入提示
    if(downWord == ''){
        msg('止损请输入11-50的整数！');
        return;
    }else if(downWord >50 || downWord <11){
        msg('止损请输入11-50的整数！');
        return;
    }else if( downWord > 50){
        msg('止损请输入11-50的整数！');
        return;
    }
    var label = $("input[type='checkbox']").is(':checked')
    if(!label){
        msg('您还没有阅读《EAI订阅协议书》');
        return;
    }
    $(obj).removeAttr('onclick');
    var typearr = [0,1];
    var cur_sell_1    = $("input[name=sellFX"+typename+"]").val();
    var cur_buy_1     = $("input[name=buyFX"+typename+"]").val();
    if(type == 0){
        Jxc_dianshu      = cur_buy_1;
        Jxc_otherdianshu = cur_sell_1;
    }else{
        Jxc_dianshu      = cur_sell_1;
        Jxc_otherdianshu = cur_buy_1;
    }
    if(typename != '' && $.inArray(type, typearr) != -1  && Jxc_dianshu != '' && Jxc_otherdianshu != ''){
        $.ajax({
            url:posturl,
            type: 'post',
            data: {typename:typename,status:type,cur_point:Jxc_dianshu,other_point:Jxc_otherdianshu,target_loss_point:downWord,target_profit_point:lossWord},
            dataType: "json",
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            success: function(d){
                if(d.status == 1){
                    msg('发布策略成功！');
                    $("#lossWord").val('');
                    $("#downWord").val('');
                    window.location.href = chicang;
                }else if(d.status == 2){
                    msg('请先<a href="'+J_login+'">登录</a>！',2);
                }else{
                    msg('发布策略失败，请正确操作！');
                    window.location.reload();
                }
            }
        });
    }
}
// 取消的新增订阅窗口
function CallSingleCancel(){
    $('.CallSingle').hide();
    $('.j_zhisun').css('display','none');
}
//获取某个日期
function getdate(num){
    var now = new Date();
    var date = new Date(now.getTime() - num * 24 * 3600 * 1000);
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    return year + '-' + month + '-' + day;
}
// 提示框封装
function msg(msg,type){  //type1 text 反之 html
    var setId = 0;
    showTips();
    if(type==1){
        $('.l_tips').text(msg);
    }else{
        $('.l_tips').html(msg);
    }
    clearInterval(setId);
    setId = setInterval(function(){
        $('.l_mask').hide();
        $('.l_tips').hide();
    },2000)
}
// 止盈止损函数取模调用
function isInteger(obj) {
    return obj%1 === 0
}
// 推进止损
// 判断推进止损盈利点位是否符合大于0
function go_push(tradeid,pztypename,baosunPoint) {
    $('.j_zhisun').hide();
    Jxc_tjtradeid = tradeid;
    Jxc_tjtypename = pztypename;
    //Jxc_losspoint  = lossPoint; 
//    if(baosunPoint > 20){ //用户输入的保损值
        $('#zhisun_input').val(baosunPoint);
//    }else{
//        $('#zhisun_input').val('');
//    }

    var push_span = $("#FD"+Jxc_tjtradeid+" #last_FX"+Jxc_tjtypename).text();
    if(push_span > 20) {
        $('.j_zhisun').css('display','block');
    }else{
        msg('盈利小于20点,不能保盈');
    }
}
// 推进止损的确定按钮
function push_sure() {
    // 输入值
    var push_input = Number($('#zhisun_input').val());
    // 获取盈利点位
    var push_span = Number($("#FD"+Jxc_tjtradeid+" #last_FX"+Jxc_tjtypename).text());
    // 修改完毕,确认时,判断盈利点位 > 20, 如果不满足,则提示不能修改
    if(push_span > 20) {
        // 条件满足:  10< 输入值 < push_span/2
        if(push_input > 10 && push_input <= push_span/2) {
            $.ajax({
                type   : "post",
                url    : pushurl,
                data   : {'insureLossPoint':push_input,'tradeid':Jxc_tjtradeid},
                dataType: "json",
                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                success: function(res){
                    if(res.status == 1) { //推进止损成功
                        window.location.reload();
                        msg('推进止损成功!');
                    }else{//推进止损失败
                        msg('推进止损失败!');
                    }
                }
            })
            $('.j_zhisun').css('display','none');
            $("#FD"+Jxc_tjtradeid+" #j_tzhisun").html('保盈'+push_input);
        }else {
            msg('保盈范围不对！');
        }
    }else{
        msg('盈利小于20点,不能保盈');
    }
}
